package algorithm.fft;

public class FastFFTNodeFactory implements IFFTNodeFactory{
	private  FFTNode topNode; 
	private Trigonometry trigonometry; 
	private WorkMemory wm; 
	public FastFFTNodeFactory(int size,int dim,Trigonometry t, WorkMemory wm){
		this.wm=wm;
		trigonometry=t;
		topNode=new FFTNode(this,wm);
		FFTNode current; 
		for (int i=1; i<size; i++){
			 current=new FFTNode(this,wm);
			 current.preceeding=topNode; 
			 topNode=current; 
		} 
		 
	}
	/* (non-Javadoc)
	 * @see algorithm.fft.IFFTNodeFactory#createRootNode(int, int, int)
	 */
	public FFTNode createRootNode(int from, int to,int order){
		FFTNode rootNode=createFFTNode(from,1,to,to,FFTNode.Node_ROOT,order,null);
		rootNode.preceeding=null; 
		return rootNode; 
	}
	public final void create2FFTNodes(FFTNode[] nodes){
		nodes[0]=topNode; 
		nodes[1]=topNode.preceeding; 
		topNode=nodes[1].preceeding; 
	}
	public final FFTNode createFFTNode(){
		FFTNode freeNode=topNode; 
		topNode=topNode.preceeding;
		return freeNode;		
	}
	/* (non-Javadoc)
	 * @see algorithm.fft.IFFTNodeFactory#createFFTNode(int, int, int, int, short, int, algorithm.fft.FFTNode)
	 */
	public final FFTNode createFFTNode(int from, int step, int to,int size,short type,int order,FFTNode parent){
		FFTNode freeNode=topNode; 
		FFTNode.setInfo(freeNode,false,from, step, to, size, type,order, parent);
		topNode=topNode.preceeding;
		return freeNode;
	}
	/* (non-Javadoc)
	 * @see algorithm.fft.IFFTNodeFactory#freeNode(algorithm.fft.FFTNode)
	 */
	public final void freeNode(FFTNode node){
		node.preceeding=topNode; 
		topNode=node; 
	}
	/* (non-Javadoc)
	 * @see algorithm.fft.IFFTNodeFactory#getTrigonometry()
	 */
	public final Trigonometry getTrigonometry() {
		return trigonometry;
	}
}
